import xlrd,xlwt
import sys
import os
from xlutils.copy import copy
p=os.path.dirname(__file__)
parent_path = os.path.dirname(p)
sys.path.append(parent_path)
from ulits.order_tool import Excel
file_path_sell=parent_path+'/data/buy_order.xls'
file_path_over=parent_path+'/data/over_order.xls'
class Seller(object):
    def __init__(self,ID):
        self.ID = ID
        self.path_sell = file_path_sell
        self.path_over = file_path_over
        self.finish_list = []
    def show(self):
        excel6 = Excel(self.path_sell)
        excel6.find_data('买家订单')
        excel6.filter_seller(self.ID)
        if excel6.use_a == []:
            print('您的店铺暂无订单')
        else:
            for i in excel6.use_a:
                print(i)
        excel6.a.clear()
        excel6.use_a.clear()
        excel6.nouse_a.clear()
    def dispose(self):
        excel3 = Excel(self.path_sell)
        excel3.find_data('买家订单')
        excel3.filter_seller(self.ID)
        process_list=[]
        complete_list=[]
        for i in excel3.use_a:
            if i[-3]=='已付款待发货':
                i[-3]='已发货'
                process_list.append(i)
            else:
                complete_list.append(i)
        if process_list == []:
            print('没有可发货的订单')
        else:
            self.finish_list = process_list+complete_list + excel3.nouse_a
            excel3.correct_data(self.finish_list)
            self.finish_list.clear()
            print('所以可发货订单均已发货')
        excel3.a.clear()
        excel3.nouse_a.clear()
        excel3.use_a.clear()
    def del_c_o(self):
        excel5 = Excel(self.path_sell)
        excel5.find_data('买家订单')
        excel5.filter_seller(self.ID)
        process_cancel=[]
        other_list=[]
        for i in excel5.use_a:
            if i[-3]=='买家已取消该订单':
                process_cancel.append(i)
            else:
                other_list.append(i)
        if process_cancel == []:
            print('没有可删除的订单')
        else:
            print('已将买家取消的订单提交给第三方支付平台')
            excel5.get_head('买家订单')
            excel5.delete_all_data('买家订单',excel5.slist)
            excel5.correct_data(other_list + excel5.nouse_a)
        excel5.a.clear()
        excel5.use_a.clear()
        excel5.nouse_a.clear()
    def look_review(self):
        excel4 = Excel(self.path_over)
        excel4.find_data('订单记录')
        excel4.filter_seller(self.ID)
        if excel4.use_a == []:
            print('您的店铺暂无交易成功记录')
        else:
            for i in excel4.use_a:
                print(i)
    def vive(self):
        print('''
            1.查看订单
            2.删除订单
            3.发货
            4.查看平价
            5.退出''')
